package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var DB *gorm.DB

func Init() {
	var err error
	dsn := "root:4ay1nkal3u8ed77y@tcp(115.190.203.192:3306)/zy?charset=utf8mb4&parseTime=True&loc=Local"
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println(err)
		panic("数据库连接失败")
	}
	fmt.Println("数据库连接成功")
	err = DB.AutoMigrate(User{}, &Article{})
	if err != nil {
		fmt.Println(err)
		panic("数据迁移失败")
	}
	fmt.Println("数据迁移成功")
}
